a11y: Split GtkSearchEntryAccessible from GtkEntryAccessible
authorEmmanuele Bassi <ebassi@gnome.org>
Wed, 27 May 2020 16:54:23 +0000 (17:54 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Fri, 5 Jun 2020 19:35:10 +0000 (20:35 +0100)
Use a separate accessible object for the GtkSearchEntry, just like we
did for GtkPasswordEntry.

gtk/a11y/gtkentryaccessible.c
gtk/a11y/gtksearchentryaccessible.c [new file with mode: 0644]
gtk/a11y/gtksearchentryaccessible.h [new file with mode: 0644]
gtk/a11y/meson.build
gtk/gtk-a11y.h
gtk/gtksearchentry.c

index 74a72f68f3a1d37818c6d27d59781cd8615ce419..fc33f5b6f35f5c6fa5febd363607c69e57b6e6aa 100644 (file)
@@ -425,7 +425,10 @@ gtk_entry_accessible_get_attributes (AtkObject *accessible)
   if (widget == NULL)
     return attributes;
 
-  if (GTK_IS_ENTRY (widget) || GTK_IS_SEARCH_ENTRY (widget))
+  /* Subclasses of GtkEntryAccessible will chain up, so we need to protect
+   * the placeholder-text property access
+   */
+  if (GTK_IS_ENTRY (widget))
     g_object_get (widget, "placeholder-text", &text, NULL);
 
   if (text == NULL)
@@ -738,7 +741,7 @@ gtk_entry_accessible_finalize (GObject *object)
 static void
 gtk_entry_accessible_class_init (GtkEntryAccessibleClass *klass)
 {
-  AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
   GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
diff --git a/gtk/a11y/gtksearchentryaccessible.c b/gtk/a11y/gtksearchentryaccessible.c
new file mode 100644 (file)
index 0000000..92c68c4
--- /dev/null
@@ -0,0 +1,76 @@
+/* gtksearchentryaccessible.c: GtkWidgetAccessible for GtkSearchEntry
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtksearchentryaccessible.h"
+
+#include "gtkintl.h"
+
+struct _GtkSearchEntryAccessible
+{
+  GtkEntryAccessible parent_instance;
+};
+
+G_DEFINE_TYPE (GtkSearchEntryAccessible, gtk_search_entry_accessible, GTK_TYPE_ENTRY_ACCESSIBLE)
+
+static AtkAttributeSet *
+gtk_search_entry_accessible_get_attributes (AtkObject *accessible)
+{
+  GtkWidget *widget;
+  AtkAttributeSet *attributes;
+  AtkAttribute *placeholder_text;
+  char *text = NULL;
+
+  attributes = ATK_OBJECT_CLASS (gtk_search_entry_accessible_parent_class)->get_attributes (accessible);
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+  if (widget == NULL)
+    return attributes;
+
+  g_object_get (widget, "placeholder-text", &text, NULL);
+  if (text == NULL)
+    return attributes;
+
+  placeholder_text = g_malloc (sizeof (AtkAttribute));
+  placeholder_text->name = g_strdup ("placeholder-text");
+  placeholder_text->value = text;
+
+  attributes = g_slist_append (attributes, placeholder_text);
+
+  return attributes;
+}
+
+static void
+gtk_search_entry_accessible_class_init (GtkSearchEntryAccessibleClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_attributes = gtk_search_entry_accessible_get_attributes;
+}
+
+static void
+gtk_search_entry_accessible_init (GtkSearchEntryAccessible *self)
+{
+  AtkObject *atk_obj = ATK_OBJECT (self);
+
+  atk_obj->role = ATK_ROLE_TEXT;
+  atk_object_set_name (atk_obj, _("Search"));
+}
diff --git a/gtk/a11y/gtksearchentryaccessible.h b/gtk/a11y/gtksearchentryaccessible.h
new file mode 100644 (file)
index 0000000..4901291
--- /dev/null
@@ -0,0 +1,48 @@
+/* gtksearchentryaccessible.h: A GtkWidgetAccessible for GtkSearchEntry
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk-a11y.h> can be included directly."
+#endif
+
+#include <gtk/a11y/gtkentryaccessible.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE        (gtk_search_entry_accessible_get_type())
+#define GTK_SEARCH_ENTRY_ACCESSIBLE(obj)        (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE, GtkSearchEntryAccessible))
+#define GTK_IS_SEARCH_ENTRY_ACCESSIBLE(obj)     (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE))
+
+typedef struct _GtkSearchEntryAccessible        GtkSearchEntryAccessible;
+typedef struct _GtkSearchEntryAccessibleClass   GtkSearchEntryAccessibleClass;
+
+struct _GtkSearchEntryAccessibleClass
+{
+  GtkEntryAccessibleClass parent_class;
+};
+
+GDK_AVAILABLE_IN_ALL
+GType gtk_search_entry_accessible_get_type (void) G_GNUC_CONST;
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkSearchEntryAccessible, g_object_unref)
+
+G_END_DECLS
index 680c598b640d1ca441025c5d01b5a55e3a22d9a6..10d74907f9bb17f566535caabe804992ba93adb0 100644 (file)
@@ -38,6 +38,7 @@ a11y_sources = files([
   'gtkscalebuttonaccessible.c',
   'gtkscrollbaraccessible.c',
   'gtkscrolledwindowaccessible.c',
+  'gtksearchentryaccessible.c',
   'gtkspinbuttonaccessible.c',
   'gtkspinneraccessible.c',
   'gtkstackaccessible.c',
@@ -90,6 +91,7 @@ a11y_headers = files([
   'gtkscalebuttonaccessible.h',
   'gtkscrollbaraccessible.h',
   'gtkscrolledwindowaccessible.h',
+  'gtksearchentryaccessible.h',
   'gtkspinbuttonaccessible.h',
   'gtkspinneraccessible.h',
   'gtkstackaccessible.h',
index 1e253ec5f3097bf30d8138581d094e46006a30c9..3199b23156fccda12a7d3e8963b23d22f729b926 100644 (file)
@@ -63,6 +63,7 @@
 #include <gtk/a11y/gtkscalebuttonaccessible.h>
 #include <gtk/a11y/gtkscrolledwindowaccessible.h>
 #include <gtk/a11y/gtkscrollbaraccessible.h>
+#include <gtk/a11y/gtksearchentryaccessible.h>
 #include <gtk/a11y/gtkspinbuttonaccessible.h>
 #include <gtk/a11y/gtkspinneraccessible.h>
 #include <gtk/a11y/gtkstackaccessible.h>
index b8c224dd8439d4cdf0954f4e4cf9ccc636e08c00..0ccf639e8755dbe7d161cecd382638482e763671 100644 (file)
@@ -40,7 +40,7 @@
 #include "gtkmarshalers.h"
 #include "gtkstylecontext.h"
 #include "gtkeventcontrollerkey.h"
-#include "a11y/gtkentryaccessible.h"
+#include "a11y/gtksearchentryaccessible.h"
 
 
 /**
@@ -219,17 +219,6 @@ gtk_search_entry_get_property (GObject    *object,
     }
 }
 
-static AtkObject *
-gtk_search_entry_get_accessible (GtkWidget *widget)
-{
-  AtkObject *atk_obj;
-
-  atk_obj = GTK_WIDGET_CLASS (gtk_search_entry_parent_class)->get_accessible (widget);
-  atk_object_set_name (atk_obj, _("Search"));
-
-  return atk_obj;
-}
-
 static gboolean
 gtk_search_entry_grab_focus (GtkWidget *widget)
 {
@@ -259,7 +248,6 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
   object_class->get_property = gtk_search_entry_get_property;
   object_class->set_property = gtk_search_entry_set_property;
 
-  widget_class->get_accessible = gtk_search_entry_get_accessible;
   widget_class->grab_focus = gtk_search_entry_grab_focus;
   widget_class->mnemonic_activate = gtk_search_entry_mnemonic_activate;
 
@@ -400,7 +388,7 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
                                        "stop-search",
                                        NULL);
 
-  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE);
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, I_("entry"));
 }